/*
 * @Author: wzh
 * @Date: 2021-12-01 03:20:37
 * @LastEditTime: 2021-12-03 13:57:52
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \ESP8266_OLED7240_Arduino\src\main.cpp
 * 可以输入预定的版权声明、个性签名、空行等
 */
#include "ESP8266WiFi.h"
#include "stdio.h"
#include "Ticker.h"
#include "Arduino.h"

#include "oled.h"
#include "oledfont.h"
#include "WString.h"
#include "NET_Ctrl.h"
#include "app_clock.h"
#include "app_hoodle.h"
#include "GUI.h"
#include "key.h"


const char* ssid     = "GKDRONE";
const char* password = "rtac5300";




Ticker TIM1;


char msg[20];

bool TIM1_Flag=0;
bool LED_STATUS=0;

void TIM1_KEY_Scan()
{
    TIM1_Flag = 1;
}

void setup() {
    Serial.begin(115200);
    pinMode(2,OUTPUT);
    key_Init();
    OLED_Init();

    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);
    autoConfig(ssid,password);
    delay(1000);
    OLED_Clear();
    
    App_Clock_Init();

    TIM1.attach(0.05,TIM1_KEY_Scan);
    key_Init();



}

uint8_t app_status = 0;

// the loop function runs over and over again forever
void loop() {

    
    uint8_t temp = 0;

    if(TIM1_Flag == 1)
    {
        TIM1_Flag = 0;
        temp = key_Scan(0);
        if(temp == 1)
        {
            
            app_status++;
            if(app_status > 7)
            {
                app_status = 0;
            }
        }
    }
    

    switch (app_status)
    {
        case 0 :
            OLED_Clear();
            app_hoodle_run();
            OLED_Refresh();
            break;

        case 1 :
            OLED_Clear();
            LineTo(rand()%72,rand()%40);
            OLED_Refresh();
            break;

        case 2 :
            OLED_Clear();
            clock_refresh();
            OLED_Refresh();
            break;
        case 3 :
            OLED_Clear();
            OLED_ShowPicture(0,0,40,40,ysyx);
            OLED_Refresh();
            break;
        case 4 :
            OLED_Clear();
            DrawLine(rand()%36,rand()%40,rand()%8 + 60,rand()%8 + 16);
            OLED_Refresh();
        break;

        case 5 :
            OLED_Clear();
            DrawLine(rand()%36,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(rand()%36,rand()%40,rand()%8 + 60,rand()%8 + 16);
            OLED_Refresh();
        break;

        case 6 :
            OLED_Clear();
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            OLED_Refresh();
        break;

        case 7 :
            OLED_Clear();
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            DrawLine(24,rand()%40,rand()%8 + 60,rand()%8 + 16);
            OLED_Refresh();
        break;
        
        default:
            OLED_Clear();
            clock_refresh();
            OLED_Refresh();
            break;
    }


}

